/*
 * @Author: heinan
 * @Date: 2023-07-23 22:59:43
 * @Last Modified by: heinan
 * @Last Modified time: 2023-08-01 21:40:27
 */
"use strict";
const { Controller } = require("egg");

/**
 * @Controller 审核管理
 */
class AuditController extends Controller {
  /**
   * @Summary 审核列表
   * @Description Description
   * @Router GET /api/v1/audit
   * @Request query string province 省份
   * @Request query string city 城市
   * @Request query string county 区/县
   * @Request query string title 标题
   * @Request query string state 状态
   * @Request query Number currentPage 页码 默认 1
   * @Request query Number pageSize 单页数量 默认 20
   */
  async index() {
    const result = await this.ctx.service.audit.index(this.ctx.query);
    if (result.data.length) {
      this.ctx.body = {
        code: 1,
        msg: "查询成功！",
        ...result,
      };
    } else {
      this.ctx.body = {
        code: 0,
        msg: "暂无数据！",
        data: [],
      };
    }
  }
  /**
   * @Summary 删除审核
   * @Description Description
   * @Router DELETE /api/v1/audit/{id}
   * @Request path string *id
   */
  async destory() {
    const result = await this.ctx.service.audit.destroy(this.ctx.params);
    if (result.affectedRows) {
      this.ctx.body = {
        code: 1,
        message: "删除成功！",
      };
    } else {
      this.ctx.body = {
        code: 0,
        message: "删除失败！",
      };
    }
  }
  /**
   * @Summary 修改审核状态
   * @Description Description
   * @Router PUT /api/v1/audit/{id}
   * @Request path string *id
   * @Request body updateAudit *body
   */
  async update() {
    const result = await this.ctx.service.audit.update({
      ...this.ctx.params,
      ...this.ctx.request.body,
    });
    if (result.affectedRows) {
      this.ctx.body = {
        code: 1,
        message: "修改成功！",
      };
    } else {
      this.ctx.body = {
        code: 0,
        message: "修改失败！",
      };
    }
  }
}

module.exports = AuditController;
